$(document).ready(function() {

	$.ajax({
				type : "post",
				url : "lzw/taskTrack_queryTaskDetail.action",
				data : "taskid=" + $.cookie('tasktrackid'),
				dataType : "JSON",
				success : showPage,
				error : function(textStatus) {
					alert("Ajax请求失败，请检查本地的网络连接！");
					return false;
				}
			});

	function showPage(data) {
		var d = eval("(" + data + ")");
		if (d.errMsg == "000" || d.errMsg == "001") {
			if(d.errMsg == "001"){
				$("#accepttask").hide();
			}
			if (d.taskDetail != null) {
				$("#tNname").text(d.taskDetail.name);
				$("#stNo").text(d.taskDetail.EId);
				$("#tNo").text(d.taskDetail.id);
				$("#tContext").text(d.taskDetail.context);
				$("#tTime").text(d.taskDetail.time);
				$("#tState").text(d.taskDetail.status);
				$("#tdept").text(d.taskDetail.dept);
				$("#tPhone").text(d.taskDetail.phone);
				$("#tPeople").text(d.taskDetail.uname);
				$("#fdepts").text(d.taskDetail.leadDepts + "/"
						+ d.taskDetail.leadname);
				$("#fPhone").text(d.taskDetail.leadphone);

				var taskid = $.trim(d.taskDetail.id);
				$.cookie('tasktrackid', taskid);
				var eventid = $.trim(d.taskDetail.EId);
				$.cookie('taskEventId', eventid);
			}
		} else {
			alert(d.errMsg);
			$('#tabFrame', window.parent.document).attr("src",
					"/ag/lzw/task_list.jsp");
			return false;
		}
	}

	function showResult(data) {
		var d = eval("(" + data + ")");
		if (d.errMsg == 1) {
			$('#tabFrame', window.parent.document).attr("src",
					"/ag/lzw/task_main.jsp");
		} else {
			alert("操作失败，请重试！");
		}
	}

	$("#accepttask").click(function() {
				$.ajax({
							type : "post",
							url : "lzw/taskTrack_acceptTask.action",
							data : "taskid=" + $.trim($("#tNo").text()),
							dataType : "JSON",
							success : showResult,
							error : function(textStatus) {
								alert("Ajax请求失败，请检查本地的网络连接！");
								return false;
							}
						});
			});

	function returnPage(data) {
		var d = eval("(" + data + ")");
		if (d.errMsg == 1) {
			$('#tabFrame', window.parent.document).attr("src",
					"/ag/lzw/task_list.jsp");
		} else {
			alert("操作失败，请重试！");
		}
	}

	$("#refusetask").click(function() {
				$.ajax({
							type : "post",
							url : "lzw/taskTrack_refuseTask.action",
							data : "taskid=" + $.trim($("#tNo").text()),
							dataType : "JSON",
							success : returnPage,
							error : function(textStatus) {
								alert("Ajax请求失败，请检查本地的网络连接！");
								return false;
							}
						});
			});
});
